package com.work04;

public class Producer extends Thread{
    private Box box;

    public Producer(Box box) {
        this.box = box;
    }

    @Override
    public void run() {

        while (true){
            synchronized(box.getObj()){
                if (box.getSum()==0){
                    break;
                }else {
                    if (box.isXiangzi()){
                        try {
                            box.getObj().wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }else {
                        System.out.println("生产了一瓶");
                        box.setXiangzi(true);
                        box.getObj().notifyAll();
                    }
                }
            }
        }
    }
}
